<!DOCTYPE html>
<html lang="en" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns:th="http://www.thymeleaf.org"
>
<!--        工商报表        -->

<head>

    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/css/custom.form.css">

</head>
<style>
    .cx > div {
        margin-bottom: 10px;
    }
</style>
<body>

<div class="dept-table">
    <!--  ---------------------------------搜索条件  -->
    <div id="searchParam" >
        <div class="layui-form-item cx">
            <div class="layui-input-inline">
                <input type="text" id="enterprise_name" class="layui-input" autocomplete="off" placeholder="请输入企业名称">
            </div>
            <div class="layui-input-inline">
                <input type="text" id="social_credit_code" class="layui-input" autocomplete="off"
                       placeholder="请输入统一社会信用代码">
            </div>
            <div class="layui-input-inline">
                <input type="text" id="registration_number" class="layui-input" autocomplete="off" placeholder="请输入注册号">
            </div>
            <div class="layui-input-inline">
                <input type="text" id="registration_authority" class="layui-input" autocomplete="off"
                       placeholder="请输入登录机关">
            </div>
            <div class="layui-input-inline">
                <input type="text" id="domination" class="layui-input" autocomplete="off" placeholder="请输入管辖机关">
            </div>
            <div class="layui-input-inline">
                <input type="text" id="address" class="layui-input" autocomplete="off" placeholder="请输入地址">
            </div>
            <div class="layui-input-inline">
                <input type="text" id="contact_number" class="layui-input" autocomplete="off" placeholder="请输入联系电话">
            </div>
            <div class="layui-input-inline">
                <input type="text" readonly class="layui-input" id="date_of_establishment" placeholder="请选择成立日期">
            </div>
            <div class="layui-input-inline">
                <input type="text" readonly class="layui-input" id="approval_date" placeholder="请选择核准日期">
            </div>
            <div class="layui-input-inline layui-form">
                <input type="text" class="layui-input" id="enterprise_status" placeholder="请输入企业状态">
            </div>
            <div class="layui-input-inline">
                <input type="text" id="liaison_man_name" class="layui-input" autocomplete="off" placeholder="请输入联络员姓名">
            </div>
            <div class="layui-input-inline">
                <input type="text" id="liaison_man_phone" class="layui-input" autocomplete="off"
                       placeholder="请输入联络员手机号码">
            </div>
            <div class="layui-input-inline">
                <input type="text" readonly class="layui-input" id="create_time" placeholder="请选择创建日期">
            </div>
            <div class="layui-input-inline layui-form">
                <select id="report_status">
                    <option value="0">请选择企业上报状态</option>
                    <option value="1">已上报</option>
                    <option value="2">未上报</option>
                </select>
            </div>
            <div class="layui-input-inline layui-form">
                <select id="enterprise_type">
                    <option value="0">请选择企业类型</option>
                    <option value="1">企业</option>
                    <option value="2">农合社</option>
                    <option value="3">个人</option>
                </select>
            </div>
            <div class="layui-input-inline layui-form">
                <select id="matching">
                    <option value="0">请选择匹配状态</option>
                    <option value="1">已匹配</option>
                    <option value="2">未匹配</option>
                </select>
            </div>
            <div class="layui-input-inline ">
                <button class="layui-btn" onclick="search()" id="search">查询</button>
            </div>
<!--            <div><a href="/rpt/annualReportDownloadExcel">下载</a></div>-->
        </div>
    </div>

    <!--  -------------------------上传弹出框  -->
    <div class="upload-report" hidden>
        <div style="height: 40px;background-color: #009688">
            <span style="line-height: 40px;color: white;letter-spacing: 5px;margin-left: 5px">上报信息</span>
            <a class="layui-btn" href="javascript:;" onclick="uploadClose()" style="width: 40px;float: right">
                <i style="margin-right: -8px;" class="layui-icon layui-icon-close"></i>
            </a>
        </div>
        <div class="layui-input-inline layui-form" style="margin-top: 20px;margin-left: 25%;">
            <select id="report_status_excel">
                <option value="1">已上报</option>
                <option value="2">未上报</option>
            </select>
        </div>
        <div style="margin-left: 25%;margin-top: 20px;">
            <button style="width: 212px;height: 40px;letter-spacing: 5px;" class="layui-btn layui-btn-sm" id="uploadAnnualExcel">选择文件</button>
        </div>
    </div>

    <!--  ------------------------------表格  -->
    <table class="layui-table" id="annualsTable" lay-filter="annualsTable"></table>
</div>
<div id="deptTree" style="display: none"></div>

<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="batchMatching" >匹配
        </button>

        <button class="layui-btn layui-btn-sm" lay-event="uploadAnnual" id="uploadAnnual" style="float: right;margin-right: -118px;">上传
        </button>
    </div>
</script>

<script src="/layui/layui.all.js"></script>
<script src="/js/core.util.js"></script>
<script>
    //获取token
    var token = CoreUtil.getData("access_token");
    //地址栏转义token中的#号
    var tokenQuery = token.replace("#", "%23");
    var tableIns2;
    var uploadIns;
    var table = layui.table;
    var upload = layui.upload;
    var form = layui.form;
    var layer = layui.layer;
    var $ = jQuery = layui.jquery;
    var laydate = layui.laydate;
    var tree = layui.tree;
    var transfer = layui.transfer;
    var deptNo = null;
    var startDateOfEstablishment = null;
    var endDateOfEstablishment = null;
    var startApprovalDate = null;
    var endApprovalDate = null;
    var createStartTime = null;
    var createEndTime = null;
    layui.use(['table', 'layer', 'laydate', 'tree', 'transfer', 'upload'], function () {
        tableIns2 = table.render({
            elem: '#annualsTable'// 表格id
            , contentType: 'application/json'
            , headers: {"authorization": token}
            , page: true //开启分页
            , limits: [10,100,1000,10000]
            , limit: 10 //每页默认显示的数量
            , url: '/rpt/findAllAnnualReport' //数据接口
            , method: 'POST'
            , toolbar: '#toolbar'
            , defaultToolbar: []
            , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                console.log(res);
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": CoreUtil.isEmpty(res.data.list) ? 0 : res.data.total, //解析数据长度
                    "data": CoreUtil.isEmpty(res.data.list) ? null : res.data.list //解析数据列表
                }
            },
            cols: [
                [
                    {field: 'enterpriseName', title: '企业名称', width: 250},
                    {field: 'socialCreditCode', title: '统一社会信用代码', width: 200},
                    {field: 'registrationNumber', title: '注册号', width: 150},
                    {field: 'registrationAuthority', title: '登录机关', width: 200},
                    {field: 'domination', title: '管辖机关', width: 190},
                    {field: 'address', title: '地址', width: 250},
                    {field: 'contactNumber', title: '联系电话', width: 125},
                    {
                        field: 'establishDate', title: '成立日期', width: 140, templet: function (item) {
                            return "<div>" + layui.util.toDateString(item.establishDate, 'yyyy年MM月dd日') + "</div>";
                        }
                    },
                    {
                        field: 'approvalDate', title: '核准日期', width: 140, templet: function (item) {
                            return "<div>" + layui.util.toDateString(item.approvalDate, 'yyyy年MM月dd日') + "</div>";
                        }
                    },
                    {field: 'enterpriseStatus', title: '状态', width: 60},
                    {field: 'liaisonManName', title: '联络员姓名', width: 100},
                    {field: 'liaisonManPhone', title: '联络员电话', width: 125},
                    {
                        field: 'createTime', title: '创建日期', width: 140, templet: function (item) {
                            return "<div>" + layui.util.toDateString(item.createTime, 'yyyy年MM月dd日') + "</div>";
                        }
                    },
                    {
                        field: 'reportStatus', title: '上报状态', width: 90, templet: function (item) {
                            if (item.reportStatus === 1 || item.reportStatus === "1") {
                                return '已上报';
                            }
                            if (item.reportStatus === 2 || item.reportStatus === "2") {
                                return '未上报';
                            }
                        }
                    },
                    {
                        field: 'enterpriseType', title: '企业类型', width: 90, templet: function (item) {
                            if (item.enterpriseType === 1 || item.enterpriseType === "1") {
                                return '企业';
                            }
                            if (item.enterpriseType === 2 || item.enterpriseType === "2") {
                                return '农合社';
                            }
                            if (item.enterpriseType === 3 || item.enterpriseType === "3") {
                                return '个人';
                            }
                        }
                    },
                    {
                        field: 'matching', title: '匹配状态', width: 90, templet: function (item) {
                            if (item.matching === 1 || item.matching === "1") {
                                return '已匹配';
                            }
                            if (item.matching === 2 || item.matching === "2") {
                                return '未匹配';
                            }
                        }
                    }
                ]
            ]
        });

        //上传事件
        uploadIns = upload.render({
            elem: '#uploadAnnualExcel'
            , before: function (obj) {
                this.data = {'reportStatus' : $("#report_status_excel").val()}
            }
            , headers: {"authorization": token}
            , url: '/rpt/annualReportUploadExcel'
            // , data: {"reportStatus" : $("#report_status_excel").val()}
            , size: '3072'
            , accept: 'file' //普通文件
            , exts: 'xlsx|xls' //允许上传的文件后缀
            , method: 'post'
            , done: function (res) { //返回值接收
                console.log(res);
                $(".upload-report").hide();
                if(res.data == 1){
                    layer.msg('导入成功！', {
                    }, function(){
                        location.reload();
                    });
                }else{
                    layer.msg('导入失败！', {
                    }, function(){
                        location.reload();
                    });
                }
            }
        });

        //操作项事件
        table.on('toolbar(annualsTable)', function (obj) {
            switch (obj.event) {
                case 'batchMatching':
                    matchingAnnual();
                    break;
                case 'uploadAnnual':
                    uploadAnnual();
                    break;
                case 'downloadAnnual':
                    downloadAnnual();
                    break;
            }
        });

        /**
         * 点击匹配事件
         */
        var matchingAnnual = function () {
            CoreUtil.sendGet("/matchingRpt/clickMatching",{},function (res) {
                console.log(res);
                layer.msg(res.data);
            })
        };

        /**
        * 点击上传按钮弹出选择框
         * 选择框选择是否是上报状态
        */
        var uploadAnnual = function (){
            $(".upload-report").show();
        };

        /**
         * 下载按钮调用接口
         */
        var downloadAnnual = function () {

            $.ajax({
                type: "post", url: "/rpt/excel", data: {}, success: function (result) {
                    if (result.status == 0) {
                        window.open(result.data)
                    }
                    if (result.message != null) {
                        layer.msg(result.message)
                    }
                }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.msg('{"status":"' + XMLHttpRequest.status + '","readyState":"' + XMLHttpRequest.readyState + '","textStatus":"' + textStatus + '","errorThrown":"' + errorThrown + '"}')
                }
            })

             // CoreUtil.sendPost("/rpt/excel", {}, function (res) {
             //     console.log(res);
             //     console.log("123");
             // });
             //    $.ajax({
             //        type:'post',
             //        url:'/rpt/excel',
             //        data:null,
             //        async:true,
             //        beforeSend: function(request) {
             //            request.setRequestHeader("authorization", CoreUtil.getData("access_token"));
             //        },
             //        success : function(msg){
             //            alert(msg);
             //        }
             //    })

        };

    });

    /**
     * 设置日期
     */
    //成立日期
    laydate.render({
        elem: '#date_of_establishment'
        , type: 'date'
        , range: '~'
        , done: function (value, date, endDate) {
            if (value != null && value != undefined && value != "") {
                startDateOfEstablishment = value.split("~")[0];
                endDateOfEstablishment = value.split("~")[1];
            } else {
                startDateOfEstablishment = null;
                endDateOfEstablishment = null;
            }
        }
    });
    //核准日期
    laydate.render({
        elem: '#approval_date'
        , type: 'date'
        , range: '~'
        , done: function (value, date, endDate) {
            if (value != null && value != undefined && value != "") {
                startApprovalDate = value.split("~")[0];
                endApprovalDate = value.split("~")[1];
            } else {
                startApprovalDate = null;
                endApprovalDate = null;
            }
        }
    });
    //创建日期
    laydate.render({
        elem: '#create_time'
        , type: 'date'
        , range: '~'
        , done: function (value, date, endDate) {
            if (value != null && value != undefined && value != "") {
                createStartTime = value.split("~")[0];
                createEndTime = value.split("~")[1];
            } else {
                createStartTime = null;
                createEndTime = null;
            }
        }
    });

    /**
     * 隐藏上传弹出框
     */
    function uploadClose() {
        $(".upload-report").hide();
    }

    /**
     * 条件查询按钮方法
     */
    function search() {
        //这里以搜索为例
        tableIns2.reload({
            where: { //设定异步数据接口的额外参数，任意设
                enterpriseName: $("#enterprise_name").val(),
                socialCreditCode: $("#social_credit_code").val(),
                registrationNumber: $("#registration_number").val(),
                registrationAuthority: $("#registration_authority").val(),
                domination: $("#domination").val(),
                address: $("#address").val(),
                contactNumber: $("#contact_number").val(),
                establishStartTime: startDateOfEstablishment,
                establishEndTime: endDateOfEstablishment,
                approvalStartTime: startApprovalDate,
                approvalEndTime: endApprovalDate,
                enterpriseStatus: $("#enterprise_status").val(),
                liaisonManName: $("#liaison_man_name").val(),
                liaisonManPhone: $("#liaison_man_phone").val(),
                createStartTime: createStartTime,
                createEndTime: createEndTime,
                reportStatus: $("#report_status").val(),
                enterpriseType: $("#enterprise_type").val(),
                matching: $("#matching").val()
            }
            , page: {
                curr: 1 //重新从第 1 页开始
            }
        });
    }
</script>
</body>
</html>